import Vue from 'vue'
import App from './App.vue'
import TDesign, {MessagePlugin} from 'tdesign-vue';
import 'tdesign-vue/es/style/index.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueRouter from 'vue-router';
import login from "@/components/login/index.vue";
import layout from "@/components/layout/index.vue";
import user from "@/components/content/user/user.vue";
import dashboard from "@/components/content/dashboard.vue";
import staff from "@/components/content/staff/staff.vue";
import role from "@/components/content/role/role.vue";
import advertising from "@/components/content/advertising/advertising.vue";
import announcement from "@/components/content/announcement/announcement.vue";
import assistant from "@/components/content/assistant/assistant.vue";
//
Vue.use(VueRouter);
Vue.use(ElementUI);
Vue.use(TDesign);
Vue.config.productionTip = false
//百度地图
import BaiduMap from 'vue-baidu-map';
import buildings from "@/components/content/buildings/buildings.vue";
import houses from "@/components/content/houses/houses.vue";
import owners from "@/components/content/owners/owners.vue";
import accounts from "@/components/content/accounts/accounts.vue";
import carports from "@/components/content/carports/carports.vue";
import cars from "@/components/content/cars/cars.vue";
import prop from "@/components/content/prop/prop.vue";
import pays from "@/components/content/pays/pays.vue";
import repairs from "@/components/content/repairs/repairs.vue";
import complains from "@/components/content/complains/complains.vue";

Vue.use(BaiduMap, {
    ak: 'wqqc95GI2btjfbjw1Oj6GZkENxpdphO9'  //这个地方是官方提供的ak密钥
})
//
let routes = [
    {path: "/login", component: login},
    {
        path: "/", component: layout,
        children: [
            {path: '/user', component: user},
            {path: '/dashboard', component: dashboard},
            {path: '/staff', component: staff},
            {path: '/role', component: role},
            {path: '/advertising', component: advertising},
            {path: '/announcement', component: announcement},
            {path: '/assistant', component: assistant},
            {path: '/buildings', component: buildings},
            {path: '/houses', component: houses},
            {path: '/owners', component: owners},
            {path: '/accounts', component: accounts},
            {path: '/carports', component: carports},
            {path: '/cars', component: cars},
            {path: '/prop', component: prop},
            {path: '/pays', component: pays},
            {path: '/repairs', component: repairs},
            {path: '/complains', component: complains},
        ]
    }

]
let router = new VueRouter({
    mode: "history",
    routes
})
//
import axios from "axios"
//配置一个拦截器
axios.interceptors.request.use(
    function (config) {
        let token = localStorage.getItem("token");
        config.headers.token = token;
        return config;
    }
)

axios.interceptors.response.use(
    function (res) {
        if (res.headers.newtoken) {
            localStorage.setItem("token", res.headers.newtoken);
        } else {
            if (res.headers.code == 406) {
                MessagePlugin.error('登录超时');
                router.push("/login");
                localStorage.removeItem("token")
            }
        }
        return res;
    },
)

new Vue({
    router,
    render: h => h(App),
}).$mount('#app')
